import {
	setUserInfo,
	setToken
} from '@/libs/auth'
import app from './modules/app';
import data from './modules/data';
import user from './modules/user';
import getter from './getters'
export const state = () => ({
	locales: ['en_US', 'zh_CN'],
	locale: 'zh_CN',
	deviceType: '', //设备类型
	loading: false,
	seo: {
		title: '',
		keywords: '',
		description: '',
	},
	menuList: [], //导航菜单
	companyInfo: {}, //店铺公司信息
	showMemberMenuWap: false, //showMemberMenuWap
	listCategory: [], //展品分类
	localeMinor:'',//小语种，默认不是小语种
})


export const mutations = {

	SET_LANG(state, locale) {
		if (state.locales.indexOf(locale) !== -1) {
			state.locale = locale
		}
	},
	SET_LANG_MINOR(state, locale) {
		state.localeMinor = locale
	},

	setDeviceType(state, v) {
		state.deviceType = v
	},
	setSeo(state, v) {
		state.seo = v
	},
	setMenuList(state, v) {
		state.menuList = v
	},
	// 店铺公司信息
	saveCompanyInfo(state, data) {
		state.companyInfo = data;
	},
	// 显示wap端个人中心菜单
	setShowMemberMenuWap(state, data) {
		state.showMemberMenuWap = data;
	},
	// 存储展品分类
	setListCategory(state, data) {
		state.listCategory = data;
	},
}

export const getters = getter

export const actions = {
	// nuxtServerInit方法会在服务端渲染被执行
	// cookie数据格式：key=value;key=value字符串
	nuxtServerInit({
		commit
	}, {
		req,
		$cookies
		}) {
		commit('SET_TOKEN', $cookies.get('pchi_token'));
		commit('SET_USER', $cookies.get('pchi_userinfo'));
	},
}

export const modules = {
	app,
	data,
	user
}
